const config = require('./config/index')
const {init} = require('./utils/router.js')
init()
App({
  onLaunch (option) {
    let system = wx.getSystemInfoSync()
    this.globalData.sdk_ver = system.SDKVersion
    // 兼容Iphone X
    this.globalData.isIpx = ~system.model.indexOf('iPhone X')
  },
  globalData: {
    userInfo: null,
    config,
    isIphoneX: false
  },
  onShow (option) {
    // 版本监测
    const updateManager = wx.getUpdateManager()
    updateManager.onCheckForUpdate(function (res) {
      if (res.hasUpdate) {
        updateManager.onUpdateReady(function () {
          wx.showModal({
            title: '更新提示',
            content: '新版本已经准备好，是否重启应用？',
            success (res) {
              if (res.confirm) {
                updateManager.applyUpdate()
              }
            }
          })
        })
      }
    })
  },
  // 最低版本支持
  checkSupport () {
    let version = this.globalData.sdk_ver
    let tempArr = version.split('.')
    if (tempArr[0] < 2) {
      return false
    } else if (tempArr[0] === 2 && tempArr[1] === 0 && tempArr[2] < 7) {
      return false
    } else {
      return true
    }
  }
})
